package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.DeliverProducts;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.ProduceProducts;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-11-10
 */
@Mapper
public interface DeliverProductsMapper extends BaseMapper<DeliverProducts> {

    @Select("<script> " +
            "SELECT M.id,M.quotes_product_id, N.name as name, M.num, N.unitName as unitName,N.specification as specification ," +
            " N.remark as vProductRemark, N.material as vProductMaterial ,M.deliver_num,M.one_num " +
            "FROM dragon_deliver_products M " +
            "LEFT JOIN " +
            "(SELECT a.id, a.name, c.name AS unitName,a.specification, a.remark, a.material " +
            "FROM dragon_vendor_products a " +
            "LEFT JOIN dragon_dictsort_detail c ON c.code_type = 'unitCode' AND a.unit = c.id) N " +
            "on M.quotes_product_id = N.id " +
            "where 1 = 1 " +
            "<if test='deliverId != null and deliverId != \"\"'>" +
            " and M.deliver_id = #{deliverId}" +
            "</if>" +
            "</script>")
    List<DeliverProducts> selectListByDeliver(Page<DeliverProducts> deliverPage, Integer deliverId);

}
